package thread;

import java.util.Scanner;

/**线程的静态方法:
 * static void sleep(long ms)
 * 该方法可以让运行这个方法的线程处于阻塞状态指定毫秒*/
public class sleepDemo {
    public static void main(String[] args) {
        System.out.println("程序开始了");
        /*简易倒计时*/
        System.out.print("请输入计时数字:");
        Scanner scanner = new Scanner(System.in);
        for (int num = scanner.nextInt(); num > 0; num--) {
            System.out.println(num);
            try {
                Thread.sleep(1000);//如果异常,只影响这一次循环,不会结束循环
            } catch (InterruptedException e) {//interupt方法中断睡眠阻塞,会抛出InterruptedException
                e.printStackTrace();
            }
        }
        System.out.println("时间到!");
        System.out.println("程序结束了");
    }
}
